//
//  NSPPPVFCView.m
//  Meboo
//
//  Created by kyo on 2024/4/30.
//

#import "NSPPPVFCView.h"
#import "NSFCPopView.h"
#import "NSPPPopView.h"
#import "NSPVPopView.h"
#import "NSVipPopView.h"
@interface NSPPPVFCView()
@property(nonatomic,strong) NSFCPopView *fcPopView;
@property(nonatomic,strong) NSPPPopView *ppPopView;
@property(nonatomic,strong) NSPVPopView *pvPopView;
@property(nonatomic,strong) NSVipPopView *vipPopView;
@end

@implementation NSPPPVFCView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public Metohd
- (void)setStyle:(FCPPVStyle)style {
    _style = style;
    if (style == MineFCStyle) {
        self.titleLab.text = [NSString stringWithFormat:@"%ld",[MBUserAccount defaultAccount].fcNum];
    } else if (style == MinePPStyle) {
        self.titleLab.text = [NSString stringWithFormat:@"%ld",[MBUserAccount defaultAccount].ppNum];
    } else if (style == MinePVStyle) {
        self.titleLab.text = [NSString stringWithFormat:@"%ld",[MBUserAccount defaultAccount].pvNum];
    }
}
#pragma mark - Action
- (void)clickFCPPPV {
    if (self.style == MineFCStyle) {
        [kKeyWindow addSubview:self.fcPopView];
        self.fcPopView.hidden = NO;
        /**
         埋点
         Me点击flash chat拉起购买弹窗 Me_Flashchat_Buy
         */
        [[NSIOApiManager sharedManager] setIOWithEventName:@"Me_Flashchat_Buy"];
    } else {
        if ([MBUserAccount defaultAccount].isVip) {
            NSString *ioStr = @"";
            if (self.style == MinePPStyle) {
                [kKeyWindow addSubview:self.ppPopView];
                self.ppPopView.hidden = NO;
                ioStr = @"Me_PP_Buy";
            } else if (self.style == MinePVStyle) {
                [kKeyWindow addSubview:self.pvPopView];
                self.pvPopView.hidden = NO;
                ioStr = @"Me_PV_Buy";
            }
            /**
             埋点
             Me点击pp拉起购买弹窗 Me_PP_Buy
             Me点击pv拉起购买弹窗 Me_PV_Buy
             */
            [[NSIOApiManager sharedManager] setIOWithEventName:ioStr];
        } else {
            [kKeyWindow addSubview:self.vipPopView];
            if (self.style == MinePPStyle) {
                self.vipPopView.index = 3;
            } else if (self.style == MinePVStyle) {
                self.vipPopView.index = 4;
            }
            self.vipPopView.hidden = NO;
            /**
             埋点
             我的页面，购买pp时是非会员状态 拉起会员订阅Me_PP_Sub
             我的页面，购买pv时是非会员状态 拉起会员订阅Me_PV_Sub
             */
            [[NSIOApiManager sharedManager] setIOWithEventName:self.style == MinePPStyle ? @"Me_PP_Sub" : @"Me_PV_Sub"];
        }
    }
}

#pragma mark - UI
- (void)setupUI {
    UITapGestureRecognizer *actionTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickFCPPPV)];
    [self addGestureRecognizer:actionTap];
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.backImageView];
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(MBHeightScale(10));
        make.centerX.equalTo(self);
    }];
    
    [self addSubview:self.subTitleLab];
    [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(MBHeightScale(-15));
        make.centerX.equalTo(self);
    }];
    
    //pop
    [self vipPopView];
    [self fcPopView];
    [self ppPopView];
    [self pvPopView];
}

#pragma mark - Setter && Getter

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.text = @"0";
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.font = MBHelBoldFontSizeScale(24);
        _titleLab.textColor = HEXS(@"000000");
    }
    return _titleLab;
}

- (UILabel *)subTitleLab {
    if (!_subTitleLab) {
        _subTitleLab = [UILabel new];
        _subTitleLab.textAlignment = NSTextAlignmentCenter;
        _subTitleLab.text = @"Flashchat";
        _subTitleLab.font = MBHelFontSizeScale(14);
        _subTitleLab.textColor = HEXS(@"000000");
    }
    return _subTitleLab;
}
- (UIImageView *)backImageView {
    if (!_backImageView) {
        _backImageView = [UIImageView new];
    }
    return _backImageView;
}

- (NSFCPopView *)fcPopView {
    if (!_fcPopView) {
        _fcPopView = [[NSFCPopView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _fcPopView.payBlock = ^{
            /**
             埋点
             Me点击flash chat拉起购买弹窗支付成功 Me_Flashchat_Buysuccess
             */
            [[NSIOApiManager sharedManager] setIOWithEventName:@"Me_Flashchat_Buysuccess"];
        };
    }
    return _fcPopView;
}

- (NSPPPopView *)ppPopView {
    if (!_ppPopView) {
        _ppPopView = [[NSPPPopView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _ppPopView.payBlock = ^{
            /**
             埋点
             Me点击pp拉起购买弹窗支付成功 Me_PP_Buysuccess
             */
            [[NSIOApiManager sharedManager] setIOWithEventName:@"Me_PP_Buysuccess"];
        };
    }
    return _ppPopView;
}

- (NSPVPopView *)pvPopView {
    if (!_pvPopView) {
        _pvPopView = [[NSPVPopView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _pvPopView.payBlock = ^{
            /**
             埋点
             Me点击pv拉起购买弹窗支付成功 Me_PV_Buysuccess
             */
            [[NSIOApiManager sharedManager] setIOWithEventName:@"Me_PV_Buysuccess"];
        };
    }
    return _pvPopView;
}

- (NSVipPopView *)vipPopView {
    if (!_vipPopView) {
        _vipPopView = [[NSVipPopView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _vipPopView.payBlock = ^{
            /**
             埋点
             我的页面，购买pp时是非会员状态 拉起会员订阅支付成功Me_PP_Subsuccess
             我的页面，购买pv时是非会员状态 拉起会员订阅支付成功Me_PV_Subsuccess
             */
            [[NSIOApiManager sharedManager] setIOWithEventName:self.style == MinePPStyle ? @"Me_PP_Subsuccess" : @"Me_PV_Subsuccess"];
        };
    }
    return _vipPopView;
}

@end
